* Table 8
local table "Table8"
local nrows=30
use "./data/citations.dta", clear
*Restrict to citations of econ journals
keep if econ==1
qui putexcel set "./tables/tables.xlsx", sheet("`table'") modify
* Citations in 2001-2020 from articles pub up to 2019
gsort author -cit0120
* Compute h-index
by author: gen nord1=_n
gen dum1=(nord1<=cit0120)*nord1
egen h1=max(dum1), by(author)
* Citations in 2001-2020 for articles pub 2000-2019 
gen cit0120sub=cit0120 if yearpub>1999
recode cit0120sub (.=0)
* Compute h-index
gsort author -cit0120sub
by author: gen nord2=_n
gen dum2=(nord2<=cit0120sub)*nord2
egen h2=max(dum2), by(author)
collapse h* (sum) cit01* , by(author person_id)
addcuraff
gsort -cit0120sub
gen nord2=_n
gsort -cit0120
gen nord1=_n
mkmat cit0120 in 1/`nrows', mat(P1) 
mkmat h1 in 1/`nrows', mat(P2)
mkmat cit0120sub in 1/`nrows', mat(P3)
mkmat h2 in 1/`nrows', mat(P4)
qui putexcel A1=("author")
forval i=1/`nrows' {
local j=`i'+1
local na=author[`i']
local af=curaff[`i']
qui putexcel A`j'="`na'"
qui putexcel B`j'="`af'"
}
qui putexcel C1=("# Cit")
qui putexcel D1=(" h")
qui putexcel E1=("# Cit")
qui putexcel F1=(" h ")
qui putexcel C2=matrix(P1)
qui putexcel D2=matrix(P2)
qui putexcel E2=matrix(P3)
qui putexcel F2=matrix(P4)

